< previous page page_801 next page >

Page 801
Specifying the Data Sources
In addition to telling the database engine what information you want, you must tell it in which table to find the information. This is done with the FROM clause of the SELECT statement. Here is the general form of the FROM clause:
FROM table1 [IN data1] [AS alias1][,table2 [IN data2] [AS alias2]]
Various options of the FROM clause are discussed in the following sections.
Specifying the Table Names
The simplest form of the FROM clause is used to specify a single table. This is the form of the clause used in this statement:
SELECT * FROM Sales
The FROM clause can also be used to specify multiple tables (refer to Listing C.1). When specifying multiple tables, separate the table names with commas. Also, if a table name has an embedded space, the table name must be enclosed in square brackets, [] (refer to Listing C.1).
Using Tables in Other Databases
As you develop more applications, you might have to pull data together from tables in different databases. For example, you might have a ZIP code database that contains the city, state, and ZIP code for every postal code in the United States. You do not want to have to duplicate this information in a table for each of your database applications that requires it. The SELECT statement lets you store that information once in its own database and then pull it in as needed. To retrieve the information from a database other than the current one, you use the IN portion of the FROM clause. The SELECT statement for retrieving the ZIP code information along with the customer data is shown in Listing C.4.
Listing C.4 GETCUST.TXTRetrieving Information from More than One Database
'**************************************************************
'We are working from the TRITON database which is already open.
'**************************************************************
SELECT Customers.Lastname, Customers.Firstname, Zipcode.City, _
    Zipcode.State  FROM Customers, Zipcode IN USZIPS  _
    WHERE Customers.Zip = Zipcode.Zip
Assigning an Alias Name to a Table
Notice the way the table name for each of the desired fields was listed in Listing C.4. Because these table names are long and there are a number of fields, the SELECT statement is fairly long. The statement gets much more complex with each field and table you add. In addition, typing long names each time increases the chances of making a typo.

 
< previous page page_801 next page >